<template>
  <el-card class="box-card" style="margin-top: 10px">
    <!-- 头部区域 -->
    <div slot="header" class="clearfix">
      <!--  @tab-click="handleClick" -->
      <!-- 左侧 -->
      <el-tabs style="width: 100%" v-model="activeName">
        <el-tab-pane label="销售额" name="first"></el-tab-pane>
        <el-tab-pane label="访问量" name="second"></el-tab-pane>
      </el-tabs>

      <!-- 右侧 -->
      <div class="right">
        <span @click="today">今日</span>
        <span @click="toweek">本周</span>
        <span @click="tomonth">本月</span>
        <span @click="toyear">本年</span>
        <el-date-picker
          v-model="data"
          value-format='yyyy-MM-dd'
          style="margin-left: 20px"
          type="daterange"
          range-separator="-"
          size="mini"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </div>
    </div>
    <!-- 内容区域 -->
    <div class="content">
      <el-row :gutter="15">
        <el-col :span="16">
          <template>
            <!-- 柱状图 -->
            <div class="bar" ref="bar"></div>
          </template>
        </el-col>
        <el-col :span="8">
          <h4>门店{{newname}}排名</h4>
          <ul>
            <li>
              <span class="rnum">1</span>
              <span>肯德基</span>
              <span>323,234</span>
            </li>
            <li>
              <span class="rnum">2</span>
              <span>麦当劳</span>
              <span>323,234</span>
            </li>
            <li>
              <span class="rnum">3</span>
              <span>肯德基</span>
              <span>323,234</span>
            </li>
            <li>
              <span class="num">4</span>
              <span>海底捞</span>
              <span>323,234</span>
            </li>
            <li>
              <span class="num">5</span>
              <span>汉堡王</span>
              <span>323,234</span>
            </li>
            <li>
              <span class="num">6</span>
              <span>华莱士</span>
              <span>323,234</span>
            </li>
            <li>
              <span class="num">7</span>
              <span>绿茶餐厅</span>
              <span>323,234</span>
            </li>
          </ul>
        </el-col>
      </el-row>
    </div>
  </el-card>
</template>

<script>
import * as echarts from "echarts";
import dayjs from 'dayjs'
export default {
  data() {
    return {
      activeName: "first",
      data:''
    };
  },
  mounted() {
    let mycharts = echarts.init(this.$refs.bar);
    mycharts.setOption({
      title: {
        text: this.newname+"趋势",
        textStyle: {
          fontSize: 15,
        },
      },
      tooltip: {
        trigger: "axis",
        axisPointer: {
          type: "shadow",
        },
      },
      grid: {
        left: "3%",
        right: "4%",
        bottom: "3%",
        containLabel: true,
      },
      xAxis: [
        {
          type: "category",
          data: [
            "一月",
            "二月",
            "三月",
            "四月",
            "五月",
            "六月",
            "七月",
            "八月",
            "九月",
            "十月",
            "十一月",
            "十二月",
          ],
          axisTick: {
            alignWithLabel: true,
          },
        },
      ],
      yAxis: [
        {
          type: "value",
        },
      ],
      series: [
        {
          name: "Direct",
          type: "bar",
          barWidth: "60%",
          data: [10, 52, 200, 334, 390, 330, 220, 25, 54, 243, 566, 353],
        },
      ],
    });
  },
  computed:{
    newname(){
        return this.activeName=='first'?'销售额':'访问量'
    }
  },
  //监听属性
  watch:{
    newname(){
        let mycharts = echarts.init(this.$refs.bar);
        mycharts.setOption({
          title: {
            text:`${this.newname}`+'趋势'
            }
    })
  }
  },
  methods:{
    today(){
        const time=dayjs().format('YYYY-MM-DD')
        this.data=[time,time]
    },
    toweek(){
        const start=dayjs().day(1).format('YYYY-MM-DD')
        const end=dayjs().day(7).format('YYYY-MM-DD')
        this.data=[start,end]
    },
    tomonth(){
        const start=dayjs().startOf('month').format('YYYY-MM-DD')
        const end=dayjs().endOf('month').format('YYYY-MM-DD')
        this.data=[start,end]
    },
    toyear(){
         const start=dayjs().startOf('year').format('YYYY-MM-DD')
        const end=dayjs().endOf('year').format('YYYY-MM-DD')
        this.data=[start,end]
    }
  }
};
</script>

<style>
.el-card__header {
  border-bottom: none;
}
.clearfix {
  position: relative;
  display: flex;
  justify-content: space-between;
}

.right {
  position: absolute;
  right: 0;
}
.right span{
    margin-right: 15px;
}
.bar {
  width: 100%;
  height: 300px;
}
h4 {
  margin-top: 0;
}
ul {
  padding-left: 0;
}
ul li {
  list-style: none;
   height: 40px;
}
.rnum {
  height: 20px;
  width: 20px;
  background-color: black;
  border-radius: 50%;
  float: left;
  color: white;
  text-align: center;
  margin-right: 20px;
}
.num{
    padding-left: 6px;
    margin-right: 25px;
}
li span:nth-child(3){ 
   float: right;
}
</style>